package com.guodi.model.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guodi.model.entity.IdtYearRelevance;
import com.guodi.model.mapper.IdtYearRelevanceMapper;
import com.guodi.model.service.IIdtYearRelevanceService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @描述：指标年份关联表 服务类
 * @作者: 彭辉
 * @日期: 2020-06-05
 */
@Service
public class IdtYearRelevanceServiceImpl extends ServiceImpl<IdtYearRelevanceMapper, IdtYearRelevance> implements IIdtYearRelevanceService {

    @Resource
    IdtYearRelevanceMapper idtYearRelevanceMapper;

    @Override
    public Integer listByKeyWordCount(String keyWord) {
        return idtYearRelevanceMapper.listByKeyWordCount(keyWord);
    }

    @Override
    public List<IdtYearRelevance> listByKeyWord(String keyWord, Integer pageSize, Integer start, String orderField, String orderType) {
        return idtYearRelevanceMapper.listByKeyWord(keyWord,pageSize,start,orderField,orderType);
    }

    @Override
    public List<IdtYearRelevance> listAll() {
        return idtYearRelevanceMapper.listAll();
    }

    @Override
    public List<IdtYearRelevance> listAllByIds(List<String> ids) {
        return idtYearRelevanceMapper.listAllByIds(ids);
    }

    @Override
    public Integer getPlanTargetYearByIndicatorId(String indicatorsId) {
        LambdaQueryWrapper<IdtYearRelevance> condition = new QueryWrapper().lambda();
        condition.select(IdtYearRelevance::getPlanTargetYear);
        condition.eq(IdtYearRelevance::getIndicatorsId, indicatorsId);
        List<IdtYearRelevance> list = list(condition);
        Integer integer = CollectionUtils.isEmpty(list) ? null : list.get(0).getPlanTargetYear();
        return integer;
    }
}